﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
//using System.Web.Script.Serialization;

using Tencent.OA.App;
using Tencent.OA.Common.Web.Security;
using System.Web.Script.Serialization;

namespace Tencent.OA.ACM.App
{
    /// <summary>
    /// 为控制器提供基类。
    /// </summary>
    public abstract class BaseController : Controller
    {

        // **************************************
        // URL: /Error
        // **************************************
        public ActionResult Error(int? errorType)
        {
            ViewData["errorType"] = errorType;
            return View();
        }

        // **************************************
        // URL: /FileNotFound
        // **************************************
        public ActionResult FileNotFound()
        {
            //Lgr.Log.Error(string.Format("{0} 不存在!", Request.RawUrl));
            return View();
        }

        // **************************************
        // URL: /AccessDeny
        // **************************************
        public ActionResult AccessDeny()
        {
            //Lgr.Log.Error(string.Format("{0} 没有权限!", Request.RawUrl));
            return View();
        }

        /// <summary>
        /// 设置一条普通的提示消息。
        /// </summary>
        /// <param name="message"></param>
        protected void SetInfoMessage(string message)
        {
            SetMessage(message, 0);
        }

        /// <summary>
        /// 设置一条操作成功的提示消息。
        /// </summary>
        /// <param name="message"></param>
        protected void SetSuccessedMessage(string message)
        {
            SetMessage(message, 1);
        }


        /// <summary>
        /// 设置一条警告消息。
        /// </summary>
        /// <param name="message"></param>
        protected void SetWarningMessage(string message)
        {
            SetMessage(message, 2);
        }
        /// <summary>
        /// 设置操作失败时显示的消息。
        /// </summary>
        /// <param name="message"></param>
        protected void SetFailedMessage(string message)
        {
            SetMessage(message, 3);
        }

        private void SetMessage(string message, int type)
        {
            StringBuilder js = new StringBuilder();
            js.AppendLine("<script type=\"text/javascript\" language=\"javascript\">");
            js.AppendLine(" $(function(){ InfoTip.showMessage(\"" + message + "\", " + type + "); });");
            js.AppendLine("</script>");
            TempData["ActionResultTempMessage"] = js.ToString();
        }
        /// <summary>
        /// 调用alert方式弹出对话框
        /// </summary>
        /// <param name="message"></param>
        protected void AlertMessage(string message)
        {
            StringBuilder js = new StringBuilder();
            js.AppendLine("<script type=\"text/javascript\" language=\"javascript\">");
            js.AppendLine(" $(function(){ alert(\"" + message + "\"); });");
            js.AppendLine("</script>");
            TempData["ActionResultTempMessage"] = js.ToString();
        }


    }
}
